import { DELETE, UPLOAD } from '@/libs';

export type UploadImageResponse = {
  url: string;
};

export type ImageInfo = {
  width: number;
  height: number;
};

/**
 * 通用图片上传
 * @param {*} params { filePath, params } = { filePath, { group,orders,type } }
 * @returns
 */
export const uploadImage = <P = Record<string, any> | Partial<ImageInfo>, D = Record<string, any>>(
  filePath: string,
  params?: P,
  data?: D
) => {
  return UPLOAD<UploadImageResponse>({
    url: '/upload/uploadFile',
    params,
    data,
    filePath,
    name: 'file'
  });
};

/**
 * 通用图片删除
 * @param {*} param0
 * @returns
 */
export const deleteImage = (path: string) => {
  return DELETE({
    url: '/picture/delete',
    data: {
      path
    }
  });
};
